package com.huaao.micropolice.core.repository.system;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.springframework.stereotype.Repository;

import com.huaao.micropolice.core.model.system.User;
import com.huaao.micropolice.core.repository.BaseDao;

@Repository
public class UserDao extends BaseDao{

	public User findByUsername(String username) {
		List<User> users = getSession().createQuery("FROM User where username = ?").setString(0, username).list();
		if(users == null || users.size() == 0){
			return null;
		}
		return users.get(0);
	}
	
	public User findByUserId(String uid){
		List<User> userlist=getSession().createQuery("FROM User where id = ?").setString(0, uid).list();
		if(userlist==null || userlist.size()==0){
			return null;
		}
		return userlist.get(0);
	}
	
	public List<User> findByDeptId(String id) {
		return getSession().createQuery("FROM User WHERE dept.id = ?").setString(0, id).list();
	}
	
	public List<User> findByJobsId(String id) {
		return getSession().createQuery("FROM User WHERE jobs.id = ?").setString(0, id).list();
	}

	public User load(String id) {
		return (User)load(User.class,id);
	}
}
